package lib.bone.admin.flow;


import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.date.DateUtil;
import lib.bone.BoneAdminApplication;
import lib.bone.access.config.cycle.NepuCycleService;
import lib.bone.access.constant.ResearchTypeConst;
import lib.bone.access.constant.WorkloadTypeConst;
import lib.bone.access.module.dict.dao.NepuTopicDictDAO;
import lib.bone.audit.workload.dao.NepuWorkloadDAO;
import lib.bone.audit.workload.domain.NepuWorkload;
import lib.bone.audit.workload.service.NepuWorkloadService;
import lib.bone.common.constant.ResponseCodeConst;
import lib.bone.common.core.domain.ResponseDTO;
import lib.bone.common.utils.JsonUtil;
import lib.bone.flow.constant.FlowTaskStatusConst;
import lib.bone.flow.constant.FlowWorkStatusConst;
import lib.bone.flow.dao.FlowTaskDAO;
import lib.bone.flow.domain.dto.FlowParam;
import lib.bone.flow.domain.entity.FlowTask;
import lib.bone.flow.domain.entity.FlowWork;
import lib.bone.flow.service.FlowWorkService;
import lib.bone.nepudata.dao.NepuPaperDAO;
import lib.bone.nepudata.dao.NepuTopicDAO;
import lib.bone.nepudata.domain.entity.NepuPaper;
import lib.bone.nepudata.domain.entity.NepuTopic;
import lib.bone.nepudata.service.NepuPaperService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;

import javax.swing.text.html.Option;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Optional;

/**
 * 流程WORK测试类
 */
@Slf4j
@SpringBootTest(classes = BoneAdminApplication.class)
public class FlowWorktest {


    @Autowired
    FlowWorkService flowWorkService;

    @Autowired
    FlowTaskDAO flowTaskDAO;

    @Autowired
    NepuTopicDictDAO nepuTopicDictDAO;

    @Autowired
    NepuWorkloadDAO nepuWorkloadDAO;

    @Autowired
    NepuTopicDAO nepuTopicDAO;

    @Autowired
    NepuWorkloadService nepuWorkloadService;

    @Autowired
    NepuCycleService cycleService;

    @Autowired
    NepuPaperDAO nepuPaperDAO;

    @Test
    void test() {

        List<FlowWork> flowWorkList = flowWorkService.getPaperNumber("paper-check-01","1926");
        List<FlowWork> list = new ArrayList<>();
        //通过的或者进行中的才会占用一次机会
//        for (FlowWork flowWork:flowWorkList){
//            if(flowWork.getFlowWorkStatus().equals(FlowWorkStatusConst.IN_PROGRESS) || flowWork.getFlowWorkStatus().equals(FlowWorkStatusConst.FINISHED)){
//                list.add(flowWork);
//            }
//        }
//        if (list.size()>=3){
//            return ResponseDTO.wrap(ResponseCodeConst.FORBIDDEN,"本考核期内计算工作量的论文已达三篇的上限");
//            //return ResponseDTO.succData(ResponseCodeConst.FORBIDDEN,"本考核期内计算工作量的论文已达三篇的上限！");
//        }
        String id = cycleService.getNowResearchCycleId();
        //通过的或者进行中的才会占用一次机会
        for (FlowWork flowWork:flowWorkList){
            if(flowWork.getFlowWorkStatus().equals(FlowWorkStatusConst.IN_PROGRESS) || flowWork.getFlowWorkStatus().equals(FlowWorkStatusConst.FINISHED)){
                Optional<NepuPaper> nepuPaper = nepuPaperDAO.findById(flowWork.getServiceId());
                if (nepuPaper.get().getCycleId().equals(id)){
                    list.add(flowWork);
                }
            }
        }
        System.out.println("dfhdrg a");
        if (list.size()>=3){
            System.out.println("asdfas");        }

    }


    @Test
    void test11() {


    }

    @Test
    void getByServiceName() throws ParseException {
        String startTime = "2022-05-06";
        String endTime = "2024-12-11";
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date startDate = null;
        Date endDate = null;
        try {
            endDate = dateFormat.parse(endTime);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        try {
            startDate = dateFormat.parse(startTime);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        System.out.println("startDate:"+startDate);
        System.out.println("endDate:"+endDate);

    }


}
